/**
 * 
 */
package me.myachievements.persistence.tag;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import me.myachievements.persistence.PersistentObject;
import me.myachievements.persistence.goal.Goal;

/**
 * @author besseym
 *
 */
public class Tag extends PersistentObject implements Comparable<Tag> {
	
	private String value;
	private Date createdOn;
	private Date updatedOn;
	
	private Set<Goal> goals;

	/**
	 * Constructor
	 */
	public Tag() {
		
		this.value = new String();
		this.createdOn = new Date();
		this.updatedOn = null;
		
		goals = new HashSet<Goal>();
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @return the createdOn
	 */
	public Date getCreatedOn() {
		return createdOn;
	}

	/**
	 * @param createdOn the createdOn to set
	 */
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	/**
	 * @return the updatedOn
	 */
	public Date getUpdatedOn() {
		return updatedOn;
	}

	/**
	 * @param updatedOn the updatedOn to set
	 */
	public void setUpdatedOn(Date updatedOn) {
		this.updatedOn = updatedOn;
	}

	/**
	 * @return the goals
	 */
	public Set<Goal> getGoals() {
		return goals;
	}

	/**
	 * @param goals the goals to set
	 */
	public void setGoals(Set<Goal> goals) {
		this.goals = goals;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Tag o) {
		return value.compareTo(o.value);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (!(obj instanceof Tag)) {
			return false;
		}
		Tag other = (Tag) obj;
		if (value == null) {
			if (other.value != null) {
				return false;
			}
		} else if (!value.equals(other.value)) {
			return false;
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Tag [value=" + value + ", createdOn=" + createdOn
				+ ", updatedOn=" + updatedOn + "]";
	}

}
